<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.zhiyi.ai.hm.core.mapper.OrganizationMapper">
    <resultMap id="BaseResultMap" type="com.zhiyi.ai.hm.core.domain.Organization">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, name, phone, realname, status, parent_id, create_time, update_time
    </sql>

    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from hm_organization
        where id = #{id,jdbcType=VARCHAR}
    </select>

    <insert id="insertSelective" parameterType="com.zhiyi.ai.hm.core.domain.Organization">
        <selectKey keyProperty="id" resultType="string" order="BEFORE">
            SELECT REPLACE(UUID(),'-','') AS id FROM DUAL
        </selectKey>
        insert into hm_organization
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="realname != null">
                realname,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="parentId != null">
                parent_id,
            </if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
            #{id,jdbcType=VARCHAR},
            </if>
            <if test="name != null">
            #{name,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
            #{phone,jdbcType=VARCHAR},
            </if>
            <if test="realname != null">
            #{realname,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
            #{status,jdbcType=INTEGER},
            </if>
            <if test="parentId != null">
            #{parentId,jdbcType=VARCHAR},
            </if>
            NOW()
        </trim>
    </insert>

    <update id="updateByIdSelective" parameterType="com.zhiyi.ai.hm.core.domain.Organization">
        update hm_organization
        <set>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone = #{phone,jdbcType=VARCHAR},
            </if>
            <if test="realname != null">
                realname = #{realname,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
            <if test="parentId != null">
                parent_id = #{parentId,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=VARCHAR}
    </update>

</mapper>